import { useNurseStore } from '@/store';
import { computed, unref } from 'vue';
// import { downloadFile } from '@tarojs/taro'

export function useImage(_url: string) {
    if (!_url) {
        return '';
    }
    if (_url.startsWith("http")) {
        return _url;
    }
    const { imageUrl } = useNurseStore();
    const temp = _url?.split(",")[0] || '';
    return unref(computed(() => `${imageUrl}/sys/common/static/${temp}`))
}

// export async function useImgUrl(_url: string) {
//     const { imageUrl } = useNurseStore()
//     return await new Promise((resolve, reject) => {
//         downloadFile({
//             url: `${imageUrl}/sys/common/static/${_url}`,
//             success: async function (res) {
//                 if (res.statusCode === 200) {
//                     resolve(res.tempFilePath)
//                 } else {
//                     reject(false)
//                 }
//             },
//             fail: async function () {
//                 reject(false)
//             }
//         })
//     })
// }









